package com.quan.configuration;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.quan.common.base.constant.CommonConstant;

/**
 * RabbitMQ配置<br>
 * 1：创建队列
 * 2：创建交换机
 * 3：将队列与交换机绑定
 * @author yhaoquan
 *
 */
@Configuration
public class RabbitMQConfiguration {
	
	
	/**
	 * 队列名称（默认队列）
	 * @return
	 */
	@Bean
	public Queue queueMessageDefault() {
		return new Queue(CommonConstant.MQ_TOPIC_MESSAGE_DEFAULT) ;
	}
	
	
	/**
	 * 交换机类型Topic Exchange
	 * 广播模式或者订阅模式
	 * @return
	 */
	@Bean
	public TopicExchange topicExchange() {
		return new TopicExchange(CommonConstant.EXCHANGE_TOPIC) ;
	}
	
	
	/**
	 * 将邮件队列与Topic交换机绑定
	 * @param queueMessageMail
	 * @param topicExchange
	 * @return
	 */
	@Bean
	public Binding bindingTopicExchangeMessage(Queue queueMessageDefault, TopicExchange topicExchange) {
		return BindingBuilder.bind(queueMessageDefault).to(topicExchange).with(CommonConstant.MQ_TOPIC_MESSAGE_DEFAULT);
	}
	
	
}
